package com.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.entity.ResumeTrainExperience;
import com.service.ResumeTrainExperienceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 简历-培训经历表 前端控制器
 * </p>
 *
 * @author Damon
 * @since 2021-04-26
 */
@RestController
@RequestMapping("/resume-train-experience")
@Api(value = "UsersController", tags = {"培训经历接口"})

public class ResumeTrainExperienceController {
    @Autowired
    private ResumeTrainExperienceService resumeTrainExperienceService;
    @RequestMapping("/listAll")
    @ApiOperation(value = "查询培训经历信息listAll", notes = "查询培训经历信息", httpMethod = "POST")
    public List<ResumeTrainExperience> listAll(){
        List<ResumeTrainExperience> list = resumeTrainExperienceService.list();
        return list;
    }

    @GetMapping("/list")
    @ApiOperation(value = "根据账户培训信息list", notes = "查询培训信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resumeid", value = "简历表ID", required = true, dataType = "string"),
    })
    public List<ResumeTrainExperience> list(String resumeid){
        QueryWrapper<ResumeTrainExperience> sql = new QueryWrapper<ResumeTrainExperience>();
        sql.lambda()
                .like(!StringUtils.isEmpty(resumeid),ResumeTrainExperience::getResumeid,resumeid);
        List<ResumeTrainExperience> list = this.resumeTrainExperienceService.list(sql);
        return list;
    }



    //支持新增或修改  Post提交  /emp/edit
    @RequestMapping("/edit")
    @PostMapping("/edit")
    @ApiOperation(value = "更改培训信息edit", notes = "编辑培训信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resumeid", value = "专家Id", required = true, dataType = "string"),
            @ApiImplicitParam(name = "modify", value = "0为增1为改", required = true, dataType = "string"),
    })
    public boolean edit(@RequestBody ResumeTrainExperience resumeTrainExperience){

        boolean res=false;
        if("0".equals(resumeTrainExperience.getModify())){
            //新增
            res = resumeTrainExperienceService.save(resumeTrainExperience);
        }else{
            //修改
            res = resumeTrainExperienceService.updateById(resumeTrainExperience);
        }
        return res;
    }


    @RequestMapping("/getById")
    @GetMapping("/getById")
    @ApiOperation(value = "查询教育信息getById", notes = "编辑教育信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resumeid", value = "专家Id", required = true, dataType = "string"),
            @ApiImplicitParam(name = "modify", value = "0为增1为改", required = true, dataType = "string"),
    })
    public ResumeTrainExperience getById(int id){
        return resumeTrainExperienceService.getById(id);
    }

    @RequestMapping("/del")
    @PostMapping("/del")
    @ApiOperation(value = "删除教育信息del", notes = "删除教育信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resumeid", value = "专家Id", required = true, dataType = "string"),
    })
    public boolean del(ResumeTrainExperience resumeTrainExperience){
        return resumeTrainExperienceService.removeById(resumeTrainExperience.getId());
    }

//
}

